package cn.stylefeng.guns.config.mqconfig;

import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
public class FirstConsumer {

    @RabbitListener(queues = {"first-queue"}, containerFactory = "rabbitListenerContainerFactory")
    public void handleMessageForFirstQueue(String message) {
        System.out.println("this is the queue : firstQueue");
        // 处理消息
        System.out.println("FirstConsumer {} handleMessage :"+message);
        JSONObject object = JSONObject.parseObject(message);
        System.out.println(object);
    }

    @RabbitListener(queues = {"second-queue"},containerFactory = "rabbitListenerContainerFactory")
    public void handMessageForSecondQueue(String message){
        System.out.println("this is the queue : second-queue");
        // 处理消息
        System.out.println("SecondConsumer {} handleMessage :"+message);
        JSONObject object = JSONObject.parseObject(message);
        System.out.print(object.getString("num")+"\t");
    }
}

